<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMessagesTable extends Migration
{
    /**
     * Run the migrations.
     * @return void
     */
    public function up()
    {
        Schema::create('messages', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('sender_id')->default(0)->comment('发送者');
            $table->text('receiver_ids')->nullable()->comment('多个接收者用,隔开');
            $table->string('title', 100)->default('')->comment('消息主题');
            $table->text('content')->nullable()->comment('消息内容');
            $table->string('file1', 100)->default('')->comment('附件');
            $table->tinyInteger('send_status')->default(0)->comment('发送状态:0已删除/1垃圾箱/2草稿箱/3已发送');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
        });
        Schema::create('message_status', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('message_id')->default(0)->comment('消息Id');
            $table->unsignedInteger('sender_id')->default(0)->comment('发送者Id');
            $table->unsignedInteger('receiver_id')->default(0)->comment('接收者Id');
            $table->tinyInteger('view_status')->default(0)->comment('0未查看/1已查看');
            $table->tinyInteger('status')->default(0)->comment('0垃圾箱/1收件箱');
            $table->dateTime('created_at')->nullable()->comment('创建时间');
            $table->dateTime('updated_at')->nullable()->comment('更新时间');
        });
    }

    /**
     * Reverse the migrations.
     * @return void
     */
    public function down()
    {
        Schema::drop('message_status');
        Schema::drop('messages');
    }
}
